package com.yxh.lib_base.network

import com.google.gson.Gson

/**
 * 作者　: yuanxh
 * 时间　: 2019/12/17
 * 描述　:自定义错误信息异常
 */
class AppException : Exception {

    var errorMsg: String //错误消息
    var errCode: Int = 0 //错误码
    var errorLog: String? //错误日志
    var throwable: Throwable? = null

    constructor(errCode: Int, error: String?, errorLog: String? = "", throwable: Throwable? = null) : super(error) {
        this.errorMsg = error ?: "请求失败，请稍后再试"
        this.errCode = errCode
        this.errorLog = errorLog ?: this.errorMsg
        this.throwable = throwable
    }

//    constructor(error: BaseNetError, e: Throwable?) {
//        errCode = error.getKey()
//        errorMsg = error.getValue()
//        errorLog = e?.message
//        throwable = e
//    }
    constructor(error: Error, e: Throwable?) {
        errCode = error.getKey()
        errorMsg = error.getValue()
        errorLog = e?.message
        throwable = e
    }
     fun toJson() =Gson().toJson(this)
}